﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Turtle8
{
    public partial class CompanyMainPanel : UserControl
    {
        readonly string path = CompanyManager.StartupPath + @"\images\";
        FileInfo fileInfo = null;

        public CompanyMainPanel()
        {
            InitializeComponent();

            string []filesArr =  Directory.GetFiles(path);
            foreach (string fileName in filesArr)
                if (fileName.StartsWith(path + "companyImage"))
                {
                    fileInfo = new FileInfo(fileName);
                    pictureBox.Image = Image.FromFile(fileName);
                    break;
                }
            this.Dock = DockStyle.Fill;

        }


        private void buttonChoosePic_Click(object sender, EventArgs e)
        {
            OpenImageFileDialog dlg = new OpenImageFileDialog();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                //disopsing and deleting old image.
                if (pictureBox.Image != null)
                {
                    pictureBox.Image.Dispose();
                    File.Delete(path + "companyImage" + fileInfo.Extension);
                }

                pictureBox.Image = Image.FromFile(dlg.FileName);
                fileInfo = new FileInfo(dlg.FileName);

                File.Copy(dlg.FileName, path + "companyImage" + fileInfo.Extension , true);
            }
        }
        
    }
}
